<template>
  <div class="permission-management">


    <el-card class="permission-list-card">
      <template #header>
        <div class="card-header">
          <div class="header-left">
          </div>
              <!-- 添加权限按钮区域 -->
    <div class="add-permission-section">
      <el-button type="primary" @click="showAddDialog = true" class="add-permission-btn" size="large">
        <el-icon>
          <Plus />
        </el-icon>
        添加权限
      </el-button>
    </div>
          <div class="header-right">
            <!-- 搜索输入框 -->
            <el-input v-model="searchKeyword" placeholder="搜索权限名称、标识或描述" 
              clearable @input="handleSearch" @clear="handleSearch" class="search-input">
              <template #prefix>
                <el-icon>
                  <Search />
                </el-icon>
              </template>
            </el-input>
            <!-- 状态过滤下拉框 -->
            <el-select v-model="statusFilter" placeholder="所有状态" class="status-select" @change="handleStatusFilterChange">
              <el-option label="所有状态" value="" />
              <el-option label="启用" value="0" />
              <el-option label="禁用" value="2" />
            </el-select>
            <!-- 重置按钮 -->
            <el-button @click="resetFilters" type="default" class="reset-button">
              <el-icon>
                <Refresh />
              </el-icon>
              重置
            </el-button>
          </div>
        </div>
      </template>

      <!-- 权限列表表格 -->
      <div class="table-container">
        <el-table :data="getFilteredPermissions()" style="width: 100%;" v-loading="loading" element-loading-text="加载中..." empty-text="暂无数据" table-layout="auto">
        <!-- 权限名称列 -->
        <el-table-column prop="permissionName" label="权限名称" min-width="150" width="180">
          <template #default="{ row }">
            <div class="permission-name">
              <el-input v-if="editingRowId === row.id" v-model="row.permissionName" placeholder="请输入权限名称" size="small" />
              <el-tooltip v-else :content="row.permissionName" placement="top">
                <span class="permission-name-text">{{ row.permissionName }}</span>
              </el-tooltip>
            </div>
          </template>
        </el-table-column>
        <!-- 权限标识列 -->
        <el-table-column prop="permissionCode" label="权限标识" min-width="200" width="220">
          <template #default="{ row }">
            <el-input v-if="editingRowId === row.id" v-model="row.permissionCode" placeholder="请输入权限标识" size="small" />
            <span v-else class="permission-code-text">{{ row.permissionCode }}</span>
          </template>
        </el-table-column>
        <!-- 权限描述列 -->
        <el-table-column prop="permissionDescription" label="描述" min-width="300" width="350">
          <template #default="{ row }">
            <el-input v-if="editingRowId === row.id" v-model="row.permissionDescription" size="small" />
            <span v-else class="permission-description-text">{{ row.permissionDescription || '暂无描述' }}</span>
          </template>
        </el-table-column>
        <!-- 状态列 -->
        <el-table-column prop="isActive" label="状态" min-width="100" width="120" align="center">
          <template #default="{ row }">
            <div v-if="editingRowId === row.id">
              <el-button 
                :type="row.isActive ? 'success' : 'danger'" 
                size="small" 
                @click="togglePermissionStatus(row)"
                style="width: 100%"
              >
                <el-icon v-if="row.isActive">
                  <Check />
                </el-icon>
                <el-icon v-else>
                  <Close />
                </el-icon>
                {{ row.isActive ? '启用中' : '禁用中' }}
              </el-button>
            </div>
            <el-tag v-else :type="getStatusType(row.isActive)">
              {{ getStatusName(row.isActive) }}
            </el-tag>
          </template>
        </el-table-column>
        <!-- 创建时间列 -->
        <el-table-column prop="createdAt" label="创建时间" min-width="180" width="200" align="center">
          <template #default="{ row }">
            {{ formatDate(row.createdAt) }}
          </template>
        </el-table-column>
        <!-- 操作列 -->
        <el-table-column label="操作" min-width="150" width="180" fixed="right" align="center">
          <template #default="{ row }">
            <div class="operation-buttons">
              <!-- 查看 -->
              <el-button type="text" size="small" class="view-btn" @click="viewPermission(row)">
                <el-icon><View /></el-icon>
              </el-button>
              <!-- 编辑/保存/取消 保持同一行展示 -->
              <template v-if="editingRowId === row.id">
                <el-button type="text" size="small" class="save-btn" @click="saveEdit(row.id)">
                  <el-icon><Check /></el-icon>
                </el-button>
                <el-button type="text" size="small" class="cancel-btn" @click="cancelEdit">
                  <el-icon><Close /></el-icon>
                </el-button>
              </template>
              <template v-else>
                <el-button type="text" size="small" class="edit-btn" @click="openEdit(row.id)">
                  <el-icon><Edit /></el-icon>
                </el-button>
                <el-button type="text" size="small" class="delete-btn" @click="deletePermissionHandler(row)">
                  <el-icon><Delete /></el-icon>
                </el-button>
              </template>
            </div>
          </template>
        </el-table-column>
      </el-table>
      </div>

      <!-- 分页组件 -->
      <div class="pagination-container">
        <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 50, 100]"
          :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </el-card>

    <!-- 添加权限对话框 -->
    <el-dialog v-model="showAddDialog" title="添加权限" width="500px">
      <el-form :model="permissionForm" :rules="permissionRules" ref="permissionFormRef" label-width="100px">
        <el-form-item label="权限名称" prop="PermissionName">
          <el-input v-model="permissionForm.PermissionName" />
        </el-form-item>
        <el-form-item label="权限标识" prop="PermissionCode">
          <el-input v-model="permissionForm.PermissionCode" />
        </el-form-item>
        <el-form-item label="描述" prop="PermissionDescription">
          <el-input v-model="permissionForm.PermissionDescription" type="textarea" :rows="3" />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="showAddDialog = false">取消</el-button>
          <el-button type="primary" @click="addPermissionHandler" :loading="addingPermission">确定</el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 权限详情对话框 -->
    <el-dialog v-model="showDetailDialog" title="权限详情" width="500px">
      <div class="permission-detail">
        <div class="detail-header">
            <h3>{{ selectedPermissionDetail.permissionName }}</h3>
            <div class="detail-meta">
              <span class="meta-item">
                <el-icon>
                  <Document />
                </el-icon>
                {{ selectedPermissionDetail.permissionCode }}
              </span>
              <span class="meta-item">
                <el-icon>
                  <Message />
                </el-icon>
                {{ selectedPermissionDetail.permissionDescription || '暂无描述' }}
              </span>
          </div>
        </div>
        <el-divider />
        <div class="detail-content">
          <el-row :gutter="20">
            <el-col :span="12">
              <div class="detail-item">
                <label>权限ID:</label>
                <span>{{ selectedPermissionDetail.id }}</span>
              </div>
              <div class="detail-item">
                <label>状态:</label>
                <el-tag :type="getStatusType(selectedPermissionDetail.isActive)">
                  {{ getStatusName(selectedPermissionDetail.isActive) }}
                </el-tag>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="detail-item">
                <label>创建时间:</label>
                <span>{{ formatDate(selectedPermissionDetail.createdAt) }}</span>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
import {
  getPermissionList,
  addPermission,
  updatePermission,
  deletePermission,
  enablePermission,
  disablePermission,
  getPermissionDetail
} from '@/api/permission'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  Plus, Search, View, Edit, Delete, Message, Document, Check, Close, Refresh
} from '@element-plus/icons-vue'

// ==================== 响应式数据定义 ====================
const loading = ref(false)
const addingPermission = ref(false)
const showAddDialog = ref(false)
const showDetailDialog = ref(false)
const editingRowId = ref(null)
let backupRow = null
const permissions = ref([])
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(10)
const searchKeyword = ref('')
const statusFilter = ref('')
const permissionFormRef = ref(null)
//新增权限的属性
const permissionForm = ref({
  PermissionName: '',
  PermissionCode: '',
  PermissionDescription: ''
})
let formSize=ref({
  page:1,
  size:10
})
const selectedPermissionDetail = ref()
let searchTimer = null

// ==================== 表单验证规则 ====================
const permissionRules = {
  name: [
    { required: true, message: '请输入权限名称', trigger: 'blur' },
    { min: 2, max: 50, message: '权限名称长度在 2 到 50 个字符', trigger: 'blur' }
  ],
  code: [
    { required: true, message: '请输入权限标识', trigger: 'blur' },
    { min: 2, max: 50, message: '权限标识长度在 2 到 50 个字符', trigger: 'blur' }
  ],
  description: [
    { max: 200, message: '描述不能超过 200 个字符', trigger: 'blur' }
  ]
}

// ==================== 计算属性 ====================


// ==================== 工具函数 ====================
const getStatusName = (status) => {  
  const statusMap = {
    true: '启用',
    false: '禁用',
  }
  return statusMap[status] || status
}

/**
 * 获取权限颜色
 * @param {string} permissionName - 权限名称
 * @returns {string} 权限头像背景色
 */
const getPermissionColor = (permissionName) => {
  if (!permissionName) return '#409eff'
  const colors = ['#409eff', '#67c23a', '#e6a23c', '#f56c6c', '#909399', '#9c27b0', '#ff9800']
  const index = permissionName.charCodeAt(0) % colors.length
  return colors[index]
}
const getStatusType = (status) => {
  const typeMap = {
    true: 'success',
    false: 'danger',
    'pending': 'warning'
  }
  return typeMap[status] || 'info'
}
const formatDate = (dateStr) => {
  if (!dateStr) return '未知'
  
  try {
    // 处理不同的日期格式
    let date
    if (typeof dateStr === 'string') {
      // 如果是ISO格式的字符串，直接创建Date对象
      if (dateStr.includes('T') || dateStr.includes('Z')) {
        date = new Date(dateStr)
      } else {
        // 处理其他格式的日期字符串
        date = new Date(dateStr.replace(/-/g, '/'))
      }
    } else if (dateStr instanceof Date) {
      date = dateStr
    } else {
      date = new Date(dateStr)
    }
    
    // 检查日期是否有效
    if (isNaN(date.getTime())) {
      return '未知'
    }
    
    // 格式化为中文日期时间
    return date.toLocaleString('zh-CN', {
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit'
    })
  } catch (e) {
    console.error('日期格式化错误:', e, '原始值:', dateStr)
    return '未知'
  }
}

// ==================== 数据加载函数 ====================
const loadPermissions = async () => {
  loading.value = true
  try {
    // 构建搜索参数
    const searchParams = {
      page: currentPage.value,
      size: pageSize.value
    }
    
    // 添加搜索关键词
    if (searchKeyword.value) {
      searchParams.keyword = searchKeyword.value
    }
    
    // 添加状态过滤
    if (statusFilter.value !== '') {
      searchParams.status = statusFilter.value
    }
    
    const res = await getPermissionList(searchParams)
    console.log('权限列表数据:', res)
    
    if (res && res.data && res.data.permissions) {
      permissions.value = res.data.permissions
      total.value = res.data.total || permissions.value.length
    } else {
      permissions.value = []
      total.value = 0
    }
  } catch (error) {
    console.error('加载权限列表失败:', error)
    permissions.value = []
    total.value = 0
    ElMessage.error('加载权限列表失败')
  }
  loading.value = false
}
// ==================== 搜索和过滤功能 ====================
/**
 * 处理搜索输入
 */
const handleSearch = () => {
  // 清除之前的定时器
  if (searchTimer) {
    clearTimeout(searchTimer)
  }
  
  // 设置防抖，300ms后执行搜索
  searchTimer = setTimeout(() => {
    loadPermissions()
  }, 300)
}

/**
 * 处理状态过滤变化
 */
const handleStatusFilterChange = () => {
  loadPermissions()
}

/**
 * 重置所有过滤器
 */
const resetFilters = () => {
  searchKeyword.value = ''
  statusFilter.value = ''
  loadPermissions()
}

/**
 * 获取过滤后的权限列表
 */
const getFilteredPermissions = () => {
  let filtered = permissions.value
  
  // 关键词搜索
  if (searchKeyword.value) {
    const keyword = searchKeyword.value.toLowerCase()
    filtered = filtered.filter(p => 
      (p.permissionName && p.permissionName.toLowerCase().includes(keyword)) ||
      (p.permissionCode && p.permissionCode.toLowerCase().includes(keyword)) ||
      (p.permissionDescription && p.permissionDescription.toLowerCase().includes(keyword))
    )
  }
  
  // 状态过滤
  if (statusFilter.value !== '') {
    const isActive = statusFilter.value === '0' // 0表示启用，2表示禁用
    filtered = filtered.filter(p => p.isActive === isActive)
  }
  
  return filtered
}
// ==================== 事件处理函数 ====================
const togglePermissionStatus = async (permission) => {
  console.log('当前状态:', permission.isActive)
  try {
    if (!permission.isActive) {
      // 当前是禁用状态，要启用
      let res = await enablePermission(permission.id)
      console.log('启用结果:', res)
      ElMessage.success('启用成功')
    } else {
      // 当前是启用状态，要禁用
      let res = await disablePermission(permission.id)
      console.log('禁用结果:', res)
      ElMessage.success('禁用成功')
    }
    // 重新加载数据
    await loadPermissions()
  } catch (error) {
    console.error('状态切换失败:', error)
    ElMessage.error('状态切换失败')
  }
}
const openEdit = (id) => {
  editingRowId.value = id
  const row = permissions.value.find(item => item.id === id)
  backupRow = { ...row }
}
const saveEdit = async (id) => {

  
 let obj= permissions.value.filter(item=>item.id===id)

 console.log(obj);
 

 let res= await updatePermission(obj[0])
 console.log(res);
 
loadPermissions()
 editingRowId.value=null
}
const cancelEdit = () => {
  if (editingRowId.value !== null && backupRow) {
    const idx = permissions.value.findIndex(item => item.id === editingRowId.value)
    if (idx !== -1) {
      Object.assign(permissions.value[idx], backupRow)
    }
  }
  editingRowId.value = null
  backupRow = null
}
const deletePermissionHandler = async (permission) => {
  try {
    await ElMessageBox.confirm(`确定要删除权限 ${permission.permissionName} 吗？`, '确认删除', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    await deletePermission(permission.id)
    ElMessage.success('删除成功')
    loadPermissions()
  } catch (e) {
    if (e !== 'cancel') {
      ElMessage.error('删除失败')
    }
  }
}
// ==================== 详情弹窗字段映射 ====================
const viewPermission = async (permission) => {
  try {
    const res = await getPermissionDetail(permission.id)
    console.log('权限详情数据:', res)
    
    if (res && res.data) {
      selectedPermissionDetail.value = res.data
    } else {
      selectedPermissionDetail.value = { ...permission }
    }
    showDetailDialog.value = true
  } catch (e) {
    console.error('获取权限详情失败:', e)
    selectedPermissionDetail.value = { ...permission }
    showDetailDialog.value = true
  }
}
const addPermissionHandler = async () => {
  if (!permissionForm.value) return
  addingPermission.value = true

await addPermission(permissionForm.value)
 loadPermissions()

 

   showAddDialog.value=false
    addingPermission.value = false
  
}
/**
 * 处理每页显示数量变化
 */
const handleSizeChange = (newSize) => {
  pageSize.value = newSize
  currentPage.value = 1 // 重置到第一页
  loadPermissions()
}

/**
 * 处理当前页变化
 */
const handleCurrentChange = (newPage) => {
  currentPage.value = newPage
  loadPermissions()
}
onMounted(() => {
  loadPermissions()
})

onUnmounted(() => {
  // 清理定时器
  if (searchTimer) {
    clearTimeout(searchTimer)
  }
})
</script>

<style scoped>
/* 权限管理主容器 */
.permission-management {
  padding: 20px;
  min-height: calc(100vh - 120px);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  z-index: 1;
  width: 100%;
  box-sizing: border-box;

}

/* 页面标题样式 */
.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #2d3748;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 添加权限按钮区域 */
.add-permission-section {
  margin-bottom: 20px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.add-permission-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 16px;
  padding: 16px 32px;
  font-weight: 600;
  font-size: 16px;
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.add-permission-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.add-permission-btn:hover::before {
  left: 100%;
}

.add-permission-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(102, 126, 234, 0.4);
}

.add-permission-btn:active {
  transform: translateY(-1px);
}

/* 权限列表卡片样式 */
.permission-list-card {
  margin-bottom: 20px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  width: 100%;
  box-sizing: border-box;
}

.permission-list-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
}

/* 表格容器 */
.table-container {
  overflow-x: auto;
  width: 100%;
  position: relative;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  padding: 0;
  margin: 0;
}

/* 卡片头部样式 */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 25px 30px;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  position: relative;
  min-height: 80px;
  box-sizing: border-box;
}

.card-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea, #764ba2);
}

/* 头部左侧按钮组 */
.header-left {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0;
}

/* 头部右侧搜索和过滤区域 */
.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0;
  margin-left: auto;
}

/* 搜索输入框 */
.search-input {
  width: 250px;
  margin-right: 15px;
}

/* 状态过滤器 */
.status-select {
  width: 140px;
  margin-right: 15px;
}

/* 重置按钮 */
.reset-button {
  border-radius: 12px;
  padding: 10px 20px;
  transition: all 0.3s ease;
  background: linear-gradient(135deg, #f7fafc 0%, #e2e8f0 100%);
  border: 1px solid rgba(226, 232, 240, 0.8);
  color: #4a5568;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.reset-button:hover {
  background: linear-gradient(135deg, #edf2f7 0%, #e2e8f0 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  color: #2d3748;
}

.reset-button:active {
  transform: translateY(0);
}

/* 权限名称样式 */
.permission-name {
  font-weight: 600;
  color: #2d3748;
  width: 100%;
}

.permission-name-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #2d3748;
  font-weight: 500;
  word-break: break-all;
}

/* 权限标识样式 */
.permission-code-text {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: #4a5568;
  border: 1px solid rgba(226, 232, 240, 0.8);
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: break-all;
}

/* 权限描述样式 */
.permission-description-text {
  color: #718096;
  font-size: 14px;
  line-height: 1.5;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: break-all;
}

/* 状态标签样式 */
.status-tag {
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.status-tag:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 状态切换按钮 */
.status-toggle-btn {
  width: 100%;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
}

/* 创建时间样式 */
.created-time {
  color: #718096;
  font-size: 13px;
  font-weight: 500;
}

/* 操作按钮组 */
.operation-buttons {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

/* 精简操作按钮尺寸，靠右区域一致 */
.operation-buttons :deep(.el-button) {
  padding: 2px 4px;
  box-shadow: none;
  font-size: 14px;
}

.operation-buttons :deep(.el-button .el-icon) {
  font-size: 16px;
  margin: 0;
}

/* 操作按钮样式 */
.view-btn {
  color: #667eea;
  transition: all 0.3s ease;
}

.view-btn:hover {
  color: #5a67d8;
  transform: scale(1.1);
}

.edit-btn {
  color: #48bb78;
  transition: all 0.3s ease;
}

.edit-btn:hover {
  color: #38a169;
  transform: scale(1.1);
}

.save-btn {
  color: #48bb78;
  transition: all 0.3s ease;
}

.save-btn:hover {
  color: #38a169;
  transform: scale(1.1);
}

.cancel-btn {
  color: #f56565;
  transition: all 0.3s ease;
}

.cancel-btn:hover {
  color: #e53e3e;
  transform: scale(1.1);
}

.delete-btn {
  color: #f56565;
  transition: all 0.3s ease;
}

.delete-btn:hover {
  color: #e53e3e;
  transform: scale(1.1);
}

/* 分页容器 */
.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 16px;
  margin: 20px 0;
  width: 100%;
  box-sizing: border-box;
}

/* 分页组件样式优化 */
:deep(.el-pagination) {
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

:deep(.el-pagination .el-pager li) {
  border-radius: 8px;
  transition: all 0.3s ease;
  font-weight: 500;
  margin: 0 2px;
}

:deep(.el-pagination .el-pager li.is-active) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

:deep(.el-pagination .el-pager li:hover) {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  transform: translateY(-1px);
}

:deep(.el-pagination .btn-prev),
:deep(.el-pagination .btn-next) {
  border-radius: 8px;
  transition: all 0.3s ease;
  margin: 0 5px;
}

:deep(.el-pagination .btn-prev:hover),
:deep(.el-pagination .btn-next:hover) {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  transform: translateY(-1px);
}

:deep(.el-pagination .el-pagination__sizes) {
  margin-right: 15px;
}

:deep(.el-pagination .el-pagination__total) {
  margin-right: 15px;
  color: #4a5568;
  font-weight: 500;
}

:deep(.el-pagination .el-pagination__jump) {
  margin-left: 15px;
}

:deep(.el-pagination .el-pagination__jump .el-input) {
  width: 60px;
  margin: 0 5px;
}

/* 权限详情样式 */
.permission-detail {
  padding: 20px;
}

/* 详情头部样式 */
.detail-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  padding: 20px;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 16px;
  border: 1px solid rgba(226, 232, 240, 0.8);
}

/* 详情头像 */
.detail-avatar {
  flex-shrink: 0;
}

/* 详情信息 */
.detail-info {
  flex: 1;
}

.detail-info h3 {
  margin: 0 0 15px 0;
  color: #2d3748;
  font-size: 24px;
  font-weight: 600;
}

/* 详情元信息 */
.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 元信息项 */
.meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #4a5568;
  font-size: 14px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  transition: all 0.3s ease;
}

.meta-item:hover {
  background: rgba(255, 255, 255, 0.9);
  transform: translateX(5px);
}

/* 详情内容区域 */
.detail-content {
  margin-top: 20px;
}

/* 详情项样式 */
.detail-item {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  border: 1px solid rgba(226, 232, 240, 0.6);
  transition: all 0.3s ease;
}

.detail-item:hover {
  background: rgba(255, 255, 255, 0.9);
  transform: translateX(5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 详情项标签 */
.detail-item label {
  width: 120px;
  font-weight: 600;
  color: #4a5568;
}

/* 详情项内容 */
.detail-item span {
  color: #2d3748;
  font-weight: 500;
}

/* 对话框底部按钮区域 */
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 15px;
  padding: 20px 30px;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-top: 1px solid rgba(226, 232, 240, 0.8);
}



/* Element Plus 组件样式增强 */
:deep(.el-button) {
  border-radius: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: none;
}

:deep(.el-button--primary) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

:deep(.el-button--primary:hover) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

:deep(.el-button--success) {
  background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
  box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
}

:deep(.el-button--danger) {
  background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
  box-shadow: 0 4px 15px rgba(245, 101, 101, 0.3);
}

:deep(.el-button--text) {
  background: transparent;
  box-shadow: none;
  color: #667eea;
  font-weight: 500;
}

:deep(.el-button--text:hover) {
  background: rgba(102, 126, 234, 0.1);
  color: #5a67d8;
  transform: none;
}

:deep(.el-input__wrapper) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(226, 232, 240, 0.8);
  transition: all 0.3s ease;
}

:deep(.el-input__wrapper:hover) {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-color: #667eea;
}

:deep(.el-input__wrapper.is-focus) {
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
  border-color: #667eea;
}

:deep(.el-select) {
  border-radius: 12px;
}

:deep(.el-select .el-input__wrapper) {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

:deep(.el-table) {
  background: transparent;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  width: 100% !important;
  min-width: 100%;
  table-layout: auto;
}

:deep(.el-table__body-wrapper) {
  overflow-x: auto;
  width: 100%;
}

:deep(.el-table__column) {
  min-width: 0;
}

:deep(.el-table__cell) {
  word-break: break-word;
  white-space: normal;
  padding: 12px 8px;
  min-width: 0;
  vertical-align: middle;
}

:deep(.el-table__inner-wrapper) {
  width: 100% !important;
}

:deep(.el-table__body) {
  width: 100% !important;
}

:deep(.el-table__header-wrapper) {
  width: 100% !important;
}

:deep(.el-table__fixed-header-wrapper) {
  width: 100% !important;
}

:deep(.el-table__header) {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  height: 56px;
}

:deep(.el-table__header th) {
  background: transparent;
  color: #2d3748;
  font-weight: 600;
  border-bottom: 2px solid rgba(226, 232, 240, 0.8);
  padding: 16px 8px;
  min-width: 0;
  white-space: nowrap;
  text-align: left;
}

:deep(.el-table__body tr) {
  transition: all 0.3s ease;
  height: 56px;
}

:deep(.el-table__body tr:hover) {
  background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
  transform: scale(1.01);
}

:deep(.el-table__body td) {
  padding: 12px 8px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.6);
  vertical-align: middle;
}

:deep(.el-tag) {
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

:deep(.el-tag:hover) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

:deep(.el-tag--success) {
  background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
  border: none;
  color: white;
}

:deep(.el-tag--danger) {
  background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
  border: none;
  color: white;
}

:deep(.el-tag--info) {
  background: linear-gradient(135deg, #a0aec0 0%, #718096 100%);
  border: none;
  color: white;
}

:deep(.el-dialog) {
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
}

:deep(.el-dialog__header) {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  padding: 25px 30px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

:deep(.el-dialog__title) {
  color: #2d3748;
  font-weight: 600;
  font-size: 18px;
}

:deep(.el-dialog__body) {
  padding: 20px;
  background: rgba(255, 255, 255, 0.95);
}

:deep(.el-form-item__label) {
  color: #4a5568;
  font-weight: 600;
}

:deep(.el-textarea__inner) {
  border-radius: 12px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  transition: all 0.3s ease;
}

:deep(.el-textarea__inner:focus) {
  border-color: #667eea;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
}

/* 加载状态样式 */
:deep(.el-loading-mask) {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
  border-radius: 16px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .permission-management {
    padding: 15px;
  }
  
  .card-header {
    padding: 20px 25px;
  }
  
  .search-input {
    width: 200px;
  }
  
  .status-select {
    width: 120px;
  }
}

@media (max-width: 768px) {
  .permission-management {
    padding: 10px;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }
  
  .add-permission-section {
    margin-bottom: 15px;
    justify-content: center;
  }
  
  .add-permission-btn {
    width: 100%;
    max-width: 300px;
    padding: 14px 24px;
    font-size: 14px;
  }
  
  .card-header {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
    padding: 20px;
    min-height: auto;
  }
  
  .header-left {
    justify-content: center;
    text-align: center;
  }
  
  .header-right {
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
  }
  
  .search-input {
    width: 100%;
    max-width: 300px;
    margin-right: 0;
    margin-bottom: 10px;
  }
  
  .status-select {
    width: 100%;
    max-width: 200px;
    margin-right: 0;
    margin-bottom: 10px;
  }
  
  .reset-button {
    width: 100%;
    max-width: 200px;
  }
  
  .detail-header {
    flex-direction: column;
    text-align: center;
    padding: 15px;
    gap: 15px;
  }
  
  .permission-list-card {
    margin: 0 0 15px 0;
    border-radius: 16px;
  }
  
  .pagination-container {
    padding: 15px;
    margin: 15px 0;
  }
  
  /* 移动端表格样式 */
  :deep(.el-table) {
    font-size: 12px;
    border-radius: 12px;
  }
  
  :deep(.el-table__body-wrapper) {
    overflow-x: auto;
    max-width: 100%;
  }
  
  :deep(.el-table__header th) {
    padding: 12px 6px;
    font-size: 12px;
  }
  
  :deep(.el-table__body td) {
    padding: 8px 6px;
    font-size: 12px;
  }
  
  .permission-name-text {
    max-width: 120px;
  }
  
  .permission-code-text {
    max-width: 150px;
    font-size: 11px;
  }
  
  .permission-description-text {
    max-width: 200px;
  }
  
  /* 移动端操作按钮 */
  .operation-buttons {
    flex-direction: column;
    gap: 5px;
  }
  
  .operation-buttons .el-button {
    padding: 4px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .permission-management {
    padding: 5px;
  }
  
  .permission-list-card {
    border-radius: 12px;
    margin: 0 0 10px 0;
  }
  
  .card-header {
    padding: 15px;
  }
  
  .add-permission-btn {
    padding: 12px 20px;
    font-size: 13px;
  }
  
  .page-title {
    font-size: 18px;
  }
  
  /* 超小屏幕表格优化 */
  :deep(.el-table) {
    font-size: 11px;
  }
  
  :deep(.el-table__header th) {
    padding: 8px 4px;
    font-size: 11px;
  }
  
  :deep(.el-table__body td) {
    padding: 6px 4px;
    font-size: 11px;
  }
  
  .permission-name-text {
    max-width: 100px;
  }
  
  .permission-code-text {
    max-width: 120px;
    font-size: 10px;
  }
  
  .permission-description-text {
    max-width: 150px;
  }
}

/* 表格行悬停效果 */
:deep(.el-table__body tr:hover td) {
  background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%) !important;
}

/* 表格内容显示优化 */
:deep(.el-table .cell) {
  word-break: break-word;
  white-space: normal;
  line-height: 1.5;
}

/* 权限名称列特殊样式 */
:deep(.el-table__body tr td:nth-child(1) .cell) {
  font-weight: 600;
  color: #2d3748;
}

/* 权限标识列特殊样式 */
:deep(.el-table__body tr td:nth-child(2) .cell) {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

/* 描述列特殊样式 */
:deep(.el-table__body tr td:nth-child(3) .cell) {
  color: #718096;
  font-size: 14px;
}

/* 状态列特殊样式 */
:deep(.el-table__body tr td:nth-child(4) .cell) {
  text-align: center;
}

/* 创建时间列特殊样式 */
:deep(.el-table__body tr td:nth-child(5) .cell) {
  color: #718096;
  font-size: 13px;
  font-weight: 500;
}

/* 操作列特殊样式 */
:deep(.el-table__body tr td:nth-child(6) .cell) {
  text-align: center;
}
</style> 